package student;

import java.util.Arrays;

public  class Student  {
    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
public boolean equals(Object o){
        //看到引用先判空
        if(o==null){
            return false;
        }else if(o instanceof Student){
            //向下转型，需要将Object类型还原为Student类型，进行Student属性的比较。
            Student stu=(Student) o;
            if(this.name.equals(stu.name)&&this.score== stu.score){
                return true;
            }else{
                return false;
            }
        }else {
            return false;
        }
}

    public static void main(String[] args) {
//        Student[] students = new Student[]{
//                new Student("zs", 78),
//                new Student("ls", 75),
//                new Student("ne", 82),
//                new Student("eg", 80),
//        };

//        Arrays.sort(students);
//        for (Student stu : students) {
//            System.out.println(stu);
//        }
        Student stu1=new Student("zs",89);
        Student stu2=new Student("zs",78);
        System.out.println(stu1.equals(stu2));
//        int[] arr=new int[]{1,2,3};
//        Object obj=arr;
//        IMessage msg=new MessageImpl();
//        Object obj1=msg;
    }



//    @Override
//    public int compareTo(Student o) {
//        if(this.score>o.score){
//            return -1;
//        }else if(this.score<o.score){
//            return 1;
//        }
//        return 0;
//    }
}
